package com.waiting.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @author bjweitingting
 * @description
 * @date 2018/7/23
 **/
public class ListRemoveTest {
    public static void main(String[] args) {
        List<String> stringList = new ArrayList<>();//数据集合
        List<Integer> integerList = new ArrayList<>();//存储remove的位置

        stringList.add("a");
        stringList.add("b");
        stringList.add("c");
        stringList.add("d");
        stringList.add("e");

        integerList.add(2);
        integerList.add(4);//此处相当于要移除最后一个数据

//        for (Integer i : integerList) {
//            stringList.remove(i);
//        }
        //在遍历中使用remore删除，会导致ConcurrentModificationException
//        for (String s : stringList) {
//            stringList.remove(s);
//        }
//        Iterator<String> stringIterator = stringList.iterator();
//        while (stringIterator.hasNext()) {
//            stringIterator.remove();
//        }
        List<Assets> assetsList = new LinkedList<>();
        Assets entity1 = new Assets("entity1");
        Assets entity2 = new Assets("entity2");
        assetsList.add(entity1);
        assetsList.add(entity2);
        for (Assets item : assetsList) {
            System.out.println(item.getName());
        }
        Iterator<Assets> assetsIterator=assetsList.iterator();
        int i=1;
        while (assetsIterator.hasNext()){
            System.out.println(i=0);
            assetsIterator.next();
            assetsIterator.remove();
            i++;
        }
//        for (Assets item : assetsList) {
//            if (item.getName()==""){
//                assetsList.remove(item);
//            }
//        }
//        System.out.println(stringList.size());
    }
}

class Assets {
    private String name;

    Assets(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}